﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Library;

namespace QLKH.PopUp.DiaLy
{
    public partial class popSuaTinh : Form
    {
        private Int16 idt = -1;
        public popSuaTinh(Int16 id)
        {
            InitializeComponent();
            idt = id;
        }

        private void popSuaTinh_Load(object sender, EventArgs e)
        {
            clTTP tinh = new clTTP();
            DataTable dtct = tinh.chitiet(idt);
            if (dtct != null && dtct.Rows.Count > 0)
            {
                cbbTentinh.Text = dtct.Rows[0]["ten"].ToString();
                txtVitri.Text = dtct.Rows[0]["vitri"].ToString();
                checkHienthi.Checked = bool.Parse(dtct.Rows[0]["hienthi"].ToString());
            }
        }

        public delegate void SuaTinh(int outid);
        // khai báo 1 kiểu hàm delegate
        public SuaTinh MyFunction;

        private void btsave_Click(object sender, EventArgs e)
        {
            if (MyFunction != null)
            {// tại đây gọi nó
                string tentinh = cbbTentinh.Text.Trim();
                Int16 vitri = Int16.Parse((txtVitri.Text.Trim() == "") ? "0" : txtVitri.Text.Trim());
                Int16 hienthi = Int16.Parse((checkHienthi.Checked) ? "1" : "0");
                string tenkhongdau = Querys.LocDau(cbbTentinh.Text.Trim()).ToLower();
                clTTP sttp = new clTTP();
                int outid = sttp.update(idt, tentinh, vitri, hienthi,tenkhongdau);
                MyFunction(outid);
            }
            this.Close();
        }

        private void btquit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
